package o;

import com.google.android.exoplayer2.upstream.cache.Cache;
import com.google.android.exoplayer2.upstream.cache.Cache.CacheException;
import java.util.Comparator;
import java.util.TreeSet;

public final class amp implements ama, Comparator<amd> {
    private long ˊ;
    private final long ˋ;
    private final TreeSet<amd> ˏ = new TreeSet(this);

    public /* synthetic */ int compare(Object obj, Object obj2) {
        return ॱ((amd) obj, (amd) obj2);
    }

    public amp(long j) {
        this.ˋ = j;
    }

    public void ˋ() {
    }

    public void ˎ(Cache cache, String str, long j, long j2) {
        ˏ(cache, j2);
    }

    public void ˋ(Cache cache, amd o_amd) {
        this.ˏ.add(o_amd);
        this.ˊ += o_amd.ˋ;
        ˏ(cache, 0);
    }

    public void ˊ(Cache cache, amd o_amd) {
        this.ˏ.remove(o_amd);
        this.ˊ -= o_amd.ˋ;
    }

    public void ˊ(Cache cache, amd o_amd, amd o_amd2) {
        ˊ(cache, o_amd);
        ˋ(cache, o_amd2);
    }

    public int ॱ(amd o_amd, amd o_amd2) {
        if (o_amd.ॱॱ - o_amd2.ॱॱ == 0) {
            return o_amd.ॱ(o_amd2);
        }
        return o_amd.ॱॱ < o_amd2.ॱॱ ? -1 : 1;
    }

    private void ˏ(Cache cache, long j) {
        while (this.ˊ + j > this.ˋ && !this.ˏ.isEmpty()) {
            try {
                cache.ˎ((amd) this.ˏ.first());
            } catch (CacheException e) {
            }
        }
    }
}
